---
title: "Conjoint Incivility - PreTest"
author: "Chiara Vargiu"
date: '2023-02-23'
output:
  html_document: default
  word_document: default
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = FALSE)
```

```{r message=FALSE, warning=FALSE, include=FALSE, paged.print=FALSE}
#LOAD PACKAGES
library(dplyr)        # Data manipulation
library(ggplot2)      # Visualization
library(ggpubr)       # Enhanced ggplot2 for plots
library(haven)        # Reading Stata data

DAT.OG <- read_dta("DataPretest.dta") %>% filter(respcheck==1)
```

# Sample characteristics
```{r}
# Gender Breakdown (Q4: 1 = Female, 2 = Male)
gender_summary <- DAT.OG %>%
  dplyr::summarise(
    Female_Percentage = mean(Q4 == 2, na.rm = TRUE) * 100,
    Male_Percentage = mean(Q4 == 1, na.rm = TRUE) * 100
  )
print(gender_summary)

# Age Summary (Q5)
age_summary <- DAT.OG %>%
  dplyr::summarise(
    Mean_Age = mean(Q5, na.rm = TRUE),
    SD_Age = sd(Q5, na.rm = TRUE)
  )
print(age_summary)

# Political Interest Breakdown (Q13: 1 = Very interested, 2 = Somewhat interested, 3 = Not interested at all)
political_interest_summary <- DAT.OG %>%
  dplyr::count(Q13) %>%
  dplyr::mutate(
    Interest = dplyr::case_when(
      Q13 == 0 ~ "Not at all",
      Q13 == 1 ~ "A little interested",
      Q13 == 2 ~ "Interested",
      Q13 == 3 ~ "Very interested",
    ),
    Percentage = (n / sum(n)) * 100
  ) %>%
  dplyr::select(Interest, n, Percentage)
print(political_interest_summary)

# Left-Right Self-Placement (Q15_1: 0-10 scale)
lr_summary <- DAT.OG %>%
  dplyr::summarise(
    Mean_LR = mean(Q15_1, na.rm = TRUE),
    SD_LR = sd(Q15_1, na.rm = TRUE)
  )
print(lr_summary)

# Political Affiliation Breakdown (Q17: 1 = Democrat, 2 = Republican, 3 = Independent)
political_affiliation_summary <- DAT.OG %>%
  dplyr::count(Q17) %>%
  dplyr::mutate(
    Affiliation = dplyr::case_when(
      Q17 == 1 ~ "Democrat",
      Q17 == 2 ~ "Republican",
      Q17 == 3 ~ "Independent"
    ),
    Percentage = (n / sum(n)) * 100
  ) %>%
  dplyr::select(Affiliation, n, Percentage)
print(political_affiliation_summary)

```

# Main analyses
```{r message=FALSE, warning=FALSE, include=FALSE, paged.print=FALSE}
#LOAD DATA
DAT.OG <- read_dta("DataPretest.dta") %>% filter(respcheck==1) %>% 
  dplyr::select(c(msgdisrepect_negative, msgdisrepect_civil, 
                  msgdisrepect_morons1, msgdisrepect_morons2, msgdisrepect_morons3, msgdisrepect_morons4,
                  msgdisrepect_einstein1, msgdisrepect_einstein2, msgdisrepect_einstein3, msgdisrepect_einstein4))

```

```{r echo=FALSE, message=FALSE, warning=FALSE, paged.print=FALSE}

DAT.MORON <- DAT.OG %>% 
  dplyr::mutate(`Insult #1` = msgdisrepect_morons1, `Insult #2` = msgdisrepect_morons2, `Insult #3` = msgdisrepect_morons3, `Insult #4` = msgdisrepect_morons4) %>% 
  dplyr::select(`Insult #1`, `Insult #2`, `Insult #3`, `Insult #4`) %>% 
  pivot_longer(cols = c(`Insult #1`, `Insult #2`, `Insult #3`, `Insult #4`), names_to = "Message", values_to = "Rating") %>% 
  dplyr::mutate(Message = factor(Message, levels = c("Insult #1", "Insult #2", "Insult #3", "Insult #4")))

DAT.EINSTEIN <- DAT.OG %>% 
  dplyr::mutate(`Ridicule #1` = msgdisrepect_einstein1, `Ridicule #2` = msgdisrepect_einstein2, `Ridicule #3` = msgdisrepect_einstein3, `Ridicule #4` = msgdisrepect_einstein4) %>% 
  dplyr::select(`Ridicule #1`, `Ridicule #2`, `Ridicule #3`, `Ridicule #4`) %>% 
  pivot_longer(cols = c(`Ridicule #1`, `Ridicule #2`, `Ridicule #3`, `Ridicule #4`), names_to = "Message", values_to = "Rating") %>% 
  dplyr::mutate(Message = factor(Message, levels = c("Ridicule #1", "Ridicule #2", "Ridicule #3", "Ridicule #4")))

DAT.COMBINED <- rbind(DAT.MORON, DAT.EINSTEIN) %>% 
  dplyr::mutate(Message = factor(Message, levels = c("Insult #1", "Insult #2", "Insult #3", "Insult #4", "Ridicule #1", "Ridicule #2", "Ridicule #3", "Ridicule #4")))

```


## Table B1 
```{r}
# Summarize Mean and SD for Messages
summary_stats <- DAT.COMBINED %>%
  group_by(Message) %>%
  summarise(
    N = n(),
    Mean = mean(Rating, na.rm = TRUE),
    SD = sd(Rating, na.rm = TRUE)
  )
print(summary_stats)
```

## Figure B1 & B2
```{r echo=FALSE, message=FALSE, warning=FALSE, paged.print=FALSE}
ggbetweenstats(data = DAT.MORON,  x = Message, y = Rating, xlabl = "Message", ylab = "Respectful-Disrespectful",
                     package = "ggsci",palette = "nrc_npg")
ggbetweenstats(data = DAT.EINSTEIN,  x = Message, y = Rating, xlabl = "Message", ylab = "Respectful-Disrespectful",
                     package = "ggsci",palette = "nrc_npg") + ylim(1,10)
```





